SET(LIB_NAME dlock)
SET(DLOCK_SRCS dlock.c pthread_mutexes.c pthread_spinlocks.c backtrace.c)
ADD_LIBRARY(${LIB_NAME} SHARED ${DLOCK_SRCS})
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES COMPILE_FLAGS "-O2 -Wall -fPIC -DDLOCK")
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES LINK_FLAGS "-nostartfiles")
TARGET_LINK_LIBRARIES(${LIB_NAME} dl)

INSTALL(TARGETS ${LIB_NAME}
  RUNTIME DESTINATION bin
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib/static)
INSTALL(FILES dlock.h DESTINATION include) 


SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")

SET(BUILD_TEST ON)
IF(BUILD_TEST)
	SET(LINK_DIRECTORIES ${LINK_DIRECTORIES} .)
	ADD_EXECUTABLE(test_noinst test_noinst.c)
	TARGET_LINK_LIBRARIES(test_noinst pthread)
		
	ADD_EXECUTABLE(test_inst test_inst.c)
	SET_TARGET_PROPERTIES(test_inst PROPERTIES COMPILE_FLAGS "-g -O2 -Wall -fPIC -DDLOCK")
	TARGET_LINK_LIBRARIES(test_inst ${LIB_NAME} pthread m)

	ADD_EXECUTABLE(perf_dlock perf.c)
	SET_TARGET_PROPERTIES(perf_dlock PROPERTIES COMPILE_FLAGS "-O2 -Wall -fPIC -DDLOCK")
	TARGET_LINK_LIBRARIES(perf_dlock ${LIB_NAME} pthread)

	ADD_EXECUTABLE(perf_nodlock perf.c)
	SET_TARGET_PROPERTIES(perf_nodlock PROPERTIES COMPILE_FLAGS " -O2 -Wall -fPIC")
	TARGET_LINK_LIBRARIES(perf_nodlock pthread)
ENDIF(BUILD_TEST)
